package com.situ.controller;

import com.situ.bean.Category;
import com.situ.service.ICategoryService;
import com.situ.util.LayData;
import com.situ.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;

@Controller
@RequestMapping("category")
public class CategoryController {
    @Autowired
    ICategoryService categoryService;

    @RequestMapping("cat")

    public String cat(){
        return "category.html";
    }



//    @RequestMapping("list")
//    @ResponseBody
//    public LayData getList(Page page, String text){
//        List<Category> list = categoryService.getAllCategories(page,text);
//        int count = categoryService.getCount(text);
//        return new LayData(count,list);
//    }

    @RequestMapping("child")
    @ResponseBody
    public LayData getchild(@RequestParam("id") int id){
        System.out.println("查询子产品");
       List<Category> list = categoryService.getChildrenCategories(id);
       LayData layData = new LayData();
       layData.setData(list);
       System.out.println(layData);
       return layData;
    }







    @RequestMapping("delete")
    @ResponseBody
    public int deleteCategory(int id){
        return categoryService.deleteCategory(id);
    }




    @RequestMapping("get")
    @ResponseBody
    public Category getCategoryById(int id){

        return categoryService.getCategoryByID(id);
    }


    @RequestMapping("getChildren")
    @ResponseBody
  public List<Category> getChildren(int id) {

        return categoryService.getChildrenCategories(id);
    }

   @RequestMapping("add")
    @ResponseBody
    public int addCategory(Category category){
       return categoryService.addCategory(category);
   }

   @RequestMapping("edit")
    @ResponseBody
    public int editCategory(Category category){
       return categoryService.editCategory(category);
   }








}











































